//
//  HMNavgationViewController.swift
//  Weibo
//
//  Created by 李学林 on 15/12/5.
//  Copyright © 2015年 tete. All rights reserved.
//

import UIKit

class HMNavgationViewController: UINavigationController ,UIGestureRecognizerDelegate{

    override func viewDidLoad() {
        super.viewDidLoad()
        
        self.interactivePopGestureRecognizer?.delegate = self

    }

    override func pushViewController(viewController: UIViewController, animated: Bool) {
        
        if childViewControllers.count != 0 {
        
            var title :String = "返回"
            
            if childViewControllers.count == 1{
                
                title = childViewControllers.first?.title ?? title
                
            }
        
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: title, target: self, action: "back")
            
            viewController.hidesBottomBarWhenPushed = true;
            
        }
        
        super.pushViewController(viewController, animated: animated)
    }
    
    
    @objc private func back(){
    
        popViewControllerAnimated(true)
    
    }
    
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        
        printLog("哈哈")
        
        
        return childViewControllers.count != 1
    }
    
}
